/* Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#include "common.h"
#include "spdm_command_impl.h"
#include "trusted_component.h"
#include "component_integrity.h"
#include "transfer/msg_transfer.h"

class Responder {
private:
    string                   deviceName;
    string                   inventoryPath;
    libspdm_data_parameter_t parameter;

    int32_t InitTransfer(uint8_t type);
    void ConfigCtx();

public:
    void                     *spdm_context;
    MsgTransfer              *msgTransfer;
    TrustedComponent         *trustedComponent;
    ComponentIntegrity       *componentIntegrity;

    Responder(const string& deviceName, const string& componentType, const string& inventoryPath);
    ~Responder();

    string getDeviceName() const;
    string getInventoryPath() const;

    void *NewSpdmCtx();
    int32_t InitSpdmCtx(uint8_t type);
    bool CheckSpdmCtx();
    void ReleaseSpdmCtx();

    int32_t InitConnection();
    uint8_t GetDigests();
    int32_t GetCertificateFromSpdm(uint8_t slot_id);
    Certificate *GetCertificate(uint8_t slot_id);
    int32_t ChallengeAuth(uint8_t slot_id);
    int32_t InitMeasurements(uint8_t slot_id);
    tuple<string, string, string, string, string> GetSignedMeasurement(vector<uint8_t> indices, uint8_t slot_id,
        const string& nonce);
};